package com.gyj.user.dao;

import com.gyj.user.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Repository
public interface UserDao extends JpaRepository<User, Long> {

    User findByNickNameContaining(String name);

    User findByLoginName(String name);

    List<User> getByCreateTimeLessThan(Date star);

    List<User> findByNickName(String nickname);

    User findById(int id);

    List<User> findByIdIn(List<Integer> ids);

    @Transactional //TransactionRequiredException不加的话会抛出事务异常
    @Modifying     //@Query注解好像只是用来查询的，但是如果配合@Modifying注解一共使用，则可以完成数据的删除、添加、更新操作
    @Query(value = "delete from boot_user where id=?1", nativeQuery = true)
    void deleteById(int id);
}
